<template>
    <div>
        <el-dialog
            :close-on-click-modal = "false"
            ref = "dialog"
            v-dialogDrag
            class="posClass"
            width="640px"
            :visible.sync="calcelDialogVisible"
            :before-close = "beforeClose"
            center>
            <el-form ref="form" :model="form" :rules="rules" class="paddLR20 marT10" :inline="true" label-width = "110px">
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="取消原因" prop = "cancelReason" class="posRelative">
                            <el-input v-model.trim="form.cancelReason" class="inputTxtWrapper" maxlength="255"></el-input>
                        </el-form-item>
                        <el-form-item label="取消时间" prop="time">
                            <el-date-picker
                                style = "width:100%"
                                v-model="form.time"
                                type="date"
                                class="inputTxtWrapper"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择时间">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item label="审核类型" prop = "auditType" class="posRelative">
                            <el-radio-group v-model="form.auditType">
                                <el-radio :label=1>需全部审核人员审核</el-radio>
                                <el-radio :label=2>至少需一人审核</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="选择审核人" prop = "examineUserIdsArr" class="posRelative">
                            <el-checkbox-group v-model="form.examineUserIdsArr">
                                <el-checkbox :label="item.id" v-for = "(item,index) of powerUserList" :key = "item.id" :index = "index" class="marL0">
                                    {{item.user_name}}({{item.staffnum}})
                                </el-checkbox>
                            </el-checkbox-group>
                        </el-form-item>
                    </el-col>
                 </el-row>
		    </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click.stop.native = "beforeClose">取消并关闭</el-button>
                <el-button type="primary" @click="cancelProAnaly">确 定</el-button>
            </span>
        </el-dialog>
        
    </div>
</template>

<script>
import http from '@/assets/js/http'
import _g from '@/assets/js/global'

export default {
    props:{
        proAnalyId : {
            type:Number,
            default : null
        },
        calcelDialogVisible:{
            type:Boolean,
            default:true
        },
        powerUserList:{
            type:Array,
        },
        proAnalyAuditCount:{
            type:Number,
            required : true
        },
    },
    mixins: [http],
    data(){
        return{
            form:{
                cancelReason : '',
                examineUserIdsArr : [],//   审核人员id数组
                auditType : 1,//   审核类型，1需全部审核人员审核通过才是通过   2至少需一人审核
                time : moment().format('YYYY-MM-DD')//..取消时间
            },

            rules: {
                cancelReason : [
                    { required: true, message: '请输入原因', trigger: 'blur' },
                ],
                examineUserIdsArr : [
                    { required: true, message: '请选择审核人', trigger: 'blur' },
                ],
                time : [
                    {required:true,message:'请选择取消时间',trigger:'blur'}
                ]
            }
        }
    },
    methods: {
        /* 关闭弹框 */
        beforeClose(str) {
            this.$refs.form.resetFields();
            this.form.cancelReason = ''
            this.form.time = moment().format('YYYY-MM-DD')
            this.form.examineUserIdsArr = []
            this.form.audit_type = 1

            this.$emit('hideCancelProAnalyDialog',str)
        },
        /* 确认取消立项分析 */
        cancelProAnaly(){
            const that = this
            const proAnalyId = that.proAnalyId//   所属立项分析id
            const cancelReason = that.form.cancelReason
            const cancelTime = that.form.time
            const auditType = parseInt(that.form.auditType)
            const examineUserIdsArr = that.form.examineUserIdsArr

            const proAnalyAuditCount = that.proAnalyAuditCount

            const data = {
                proAnalyId,
                cancelReason,
                auditType,
                examineUserIdsArr,
                proAnalyAuditCount,
                cancelTime
            }

            console.log('data = ',data)

            that.$refs.form.validate((valid) => {
                if(valid){
                    that.$confirm('是否确认?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        center: true
                    }).then(() => {
                            _g.showLoading('提交中')
                            that.apiPost('admin/task/cancelProAnaly', data).then((res) => {
                                _g.showLoading().close()
                                if(typeof res === 'string'){
                                    res = JSON.parse(res)
                                }
                                if (res.code != 200) {
                                    that.handleError(res)
                                } else {
                                    if(res.data.isSuccess === 0){             //  成功
                                        _g.toastMsg("success", res.message)
                                        that.beforeClose('取消立项分析')
                                    }else if(res.data.isSuccess === 2){
                                        _g.toastMsg("warning", res.message)
                                    }else if(res.data.isSuccess === 1){
                                        _g.toastMsg("error", res.message)
                                    }
                                }
                            })
                    }).catch(() => {});
                }
            })
        },
    },
    computed: {
        
    },
}
</script>

<style lang="less" scoped>

</style>


